package com.hafu.dao;

import com.hafu.util.DbUtil;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class UserDao {
    public boolean isLogin(String username, String password) {
        Connection conn = DbUtil.getConn();
        if (conn == null) {
            throw new RuntimeException("数据库连接失败：conn 为 null");
        }

        String sql = "select * from userlist where name = ? and pass = ?";

        try (PreparedStatement preparedStatement = conn.prepareStatement(sql)) {
            preparedStatement.setString(1, username);
            preparedStatement.setString(2, password);
            ResultSet resultSet = preparedStatement.executeQuery();
            return resultSet.next();
        } catch (SQLException throwables) {
            throwables.printStackTrace();
            throw new RuntimeException("数据库操作异常", throwables);
        }
    }
}

